package com.inossem.warehousestorage_inossem.request.query;

import android.content.Context;
import android.text.TextUtils;

import com.google.gson.Gson;
import com.inossem.warehousestorage_inossem.bean.query.QueryOutStorageListBean;
import com.inossem.warehousestorage_inossem.constant.RequestConstant;
import com.inossem.warehousestorage_inossem.listener.GsonBeanListener;
import com.inossem.warehousestorage_inossem.listener.StringRequestListener;
import com.inossem.warehousestorage_inossem.manage.RequestManage;
import com.inossem.warehousestorage_inossem.model.StringResponse;
import com.inossem.warehousestorage_inossem.request.Request;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by leij on 2017/6/12.
 */

public class QueryOutStorageListRequest extends Request {

    private static final String INVENTORY_ADDRESS_CODE = "inventoryAddressCode";//库存地点代码

    private static final String OUT_STORAGE_NUMBER = "outStorageNumber";//出库单号

    private static final String DATE_BEGIN = "sDate";//起始日期

    private static final String DATE_END = "eDate";//结束日期

    public static String request(Context context, String inventoryAddressCode, String outStorageNumber, String dateBegin, String dateEnd, GsonBeanListener gsonBeanListener) {
        String tag;
        Map<String, String> params = new HashMap<>();
        params.put(INVENTORY_ADDRESS_CODE, TextUtils.isEmpty(inventoryAddressCode) ? "" : inventoryAddressCode);
        params.put(OUT_STORAGE_NUMBER, TextUtils.isEmpty(outStorageNumber) ? "" : outStorageNumber);
        params.put(DATE_BEGIN, TextUtils.isEmpty(dateBegin) ? "" : dateBegin);
        params.put(DATE_END, TextUtils.isEmpty(dateEnd) ? "" : dateEnd);
        String url = RequestManage.getUrl(context, RequestConstant.URL_QUERY_OUT_STORAGE_LIST + RequestManage.mapEncodeToParams(params));
        tag = RequestManage.getHttpsGetWithLoading(context, url, new StringRequestListener() {
            @Override
            public void onSuccess(StringResponse stringRequestResponse) {
                Gson gson = new Gson();
                QueryOutStorageListBean bean = gson.fromJson(stringRequestResponse.getResponseInfo(), QueryOutStorageListBean.class);
                excuteJsonBean(context, bean, bean.getCode(), bean.getMsg(), gsonBeanListener);
            }
        });
        return tag;
    }

}
